package com.rock.code.bigdata.towpage.controller;

import com.rock.code.base.controller.BaseController;
import com.rock.code.bigdata.alarmanalysis.service.impl.alarmAnalysisServiceImpl;
import com.rock.code.bigdata.towpage.service.HostPageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/HostPage")
public class HostPageController extends BaseController {

    @RequestMapping("/{CI_TYPE}/{DI_QU}")
    public String host(@PathVariable("CI_TYPE") String CI_TYPE, @PathVariable("DI_QU") String DI_QU) {
        this.request.setAttribute("CI_TYPE", CI_TYPE);
        this.request.setAttribute("DI_QU", DI_QU);
        return "bigdata/towpage/HostPageView";
    }

    @Resource
    private HostPageService hostPageService;

    /**
     * 统计详情调用方法
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryTableInfo", method = RequestMethod.POST)
    public HashMap queryTableInfo(String CI_TYPE, String DI_QU) {
        HashMap map = new HashMap();
        HashMap resultMap = new HashMap();
        List list = new ArrayList();
        List list1 = new ArrayList();
        if (CI_TYPE != null && DI_QU != null) {
            map.put("CI_TYPE", CI_TYPE);
            map.put("DI_QU", DI_QU);
        }
        list = hostPageService.queryTableInfoData(map);
        list1 = hostPageService.queryTableInfoData1(map);
        resultMap.put("list", list);
        resultMap.put("list1", list1);
        return resultMap;
    }


    /**
     * 根据类别查询业务类数量
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryResourceNumber", method = RequestMethod.POST)
    public HashMap queryResourceNumber(String CI_TYPE) {
        HashMap map = new HashMap();
        HashMap resultMap = new HashMap();
        List list = new ArrayList();
        List list1 = new ArrayList();
        if (CI_TYPE != null) {
            map.put("CI_TYPE", CI_TYPE);
        }
        list = hostPageService.queryResourceNumber(map);
        list1 = hostPageService.queryResourceNumber1(map);
        resultMap.put("list", list);
        resultMap.put("list1", list1);
        return resultMap;
    }

    /**
     * 仪表盘
     *
     * @param KPI_CODE,CI_TYPE
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryYbp", method = RequestMethod.POST)
    public List queryYbp(String CI_TYPE, String KPI_CODE, String DI_QU) {
        HashMap map = new HashMap();
        String yearTableName = hostPageService.monthYearTableName();
        String lastMonth = hostPageService.lastMonth();
//                map.put("tableName", yearTableName);
        if (CI_TYPE != null && KPI_CODE != null) {
            map.put("CI_TYPE", CI_TYPE);
            map.put("KPI_CODE", KPI_CODE);
            map.put("DI_QU", DI_QU);
        }
        map.put("tableName", "tb_kpi_value_year_2018");
//                map.put("DATA_TIME", lastMonth);
        map.put("DATA_TIME", "2018-01");
        List list = hostPageService.queryYbpData(map);
        return list;
    }

    /**
     * 健康度
     *
     * @param CI_TYPE,DI_QU
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/queryJkd", method = RequestMethod.POST)
    public List queryJkd(String CI_TYPE, String DI_QU) {
        HashMap map = new HashMap();
        String startDate = alarmAnalysisServiceImpl.getLastMonthStartDate();
        String endDate = alarmAnalysisServiceImpl.getLastMonthEndDate();
        if (CI_TYPE != null && DI_QU != null) {
            map.put("CI_TYPE", CI_TYPE);
            map.put("DI_QU", DI_QU);
        }
        if (!"".equals(startDate) && !"null".equals(startDate)) {
            /*map.put("startDate", startDate);*/
            map.put("startDate", "2018-01-01 00:00:00");
        }
        if (!"".equals(endDate) && !"null".equals(endDate)) {
            /*map.put("endDate", endDate);*/
            map.put("endDate", "2018-01-31 23:59:59");
        }
        List list = hostPageService.queryJkdData(map);
        return list;
    }

    /**
     * top榜
     *
     * @param KPI_CODE
     * @return
     */
    //主机top由高到低展示
    @ResponseBody
    @RequestMapping(value = "/queryTop", method = RequestMethod.POST)
    public HashMap queryTop(String KPI_CODE, String DI_QU) {
        HashMap map = new HashMap();
        HashMap resultMap = new HashMap();
        List list = new ArrayList();
        String tableName = hostPageService.monthYearTableName();//201807
//            map.put("tableName", tableName);
        String lastMonth = hostPageService.lastMonth();
        map.put("tableName", "tb_kpi_value_year_2018");
        if (KPI_CODE != null && DI_QU != null) {
            map.put("KPI_CODE", KPI_CODE);
            map.put("DI_QU", DI_QU);
        }
//            map.put("DATA_TIME", lastMonth);
        map.put("DATA_TIME", "2018-01");
        list = hostPageService.queryTopData(map);
        resultMap.put("list", list);
        return resultMap;
    }
}